﻿<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:str="http://exslt.org/strings"
    exclude-result-prefixes="xsl x str">

	<xsl:output omit-xml-declaration="yes" method="html"/>

	<xsl:template match="a">

		<xsl:variable name="ext" select="substring(@href, string-length(@href)-3, 4)" />

		<xsl:choose>

			<xsl:when test="$ext = '.swf'">
				<xsl:call-template name="swf" />
			</xsl:when>
			<xsl:when test="$ext = '.wav'">
				<xsl:call-template name="wav" />
			</xsl:when>

			<xsl:when test="$ext = '.wmv' or $ext = '.mpg' or $ext = 'mpeg'">
				<xsl:call-template name="wmv" />
			</xsl:when>

			<xsl:otherwise>
				File extension '<xsl:value-of select="$ext"/>' not recognised
			</xsl:otherwise>

		</xsl:choose>

	</xsl:template>

	<xsl:template match="@Params">

		<xsl:for-each select="str:split(., ';')">

			<xsl:variable name="p" select="str:split(., '=')"/>

			<param>
				<xsl:attribute name="name">
					<xsl:value-of select="$p[1]"/>
				</xsl:attribute>
				<xsl:attribute name="value">
					<xsl:value-of select="$p[2]"/>
				</xsl:attribute>
			</param>

		</xsl:for-each>

	</xsl:template>

	<xsl:template name="swf">

		<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
				codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
				width="250" height="250">
			<param name="SRC" value="{@href}"/>
			<xsl:apply-templates select="/div/@Params"/>
			<embed src="{@href}" width="250" height="250" type="application/x-shockwave-flash"
				   pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" />
		</object>

	</xsl:template>

	<xsl:template name="wav">

		<object	classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95">
			<param name="FileName" value="{@href}" />
		</object>

	</xsl:template>

	<xsl:template name="wmv">
		<object	classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95">
			<param name="FileName" value="{@href}" />
		</object>
	</xsl:template>


</xsl:stylesheet>
